package com.chuangjiangx.member.manager.web.web.stored.controller;

import com.chuangjiangx.commons.response.Response;
import com.chuangjiangx.commons.response.ResponseUtils;
import com.chuangjiangx.member.basic.ddd.query.MbrCountQuery;
import com.chuangjiangx.member.manager.basic.web.controller.BaseController;
import com.chuangjiangx.member.manager.basic.web.interceptor.Login;
import com.chuangjiangx.member.manager.common.Constants;
import com.chuangjiangx.member.manager.common.ThreadLocalUser;
import com.chuangjiangx.member.manager.web.web.stored.request.MbrOrderCountInfoRequest;
import com.chuangjiangx.member.stored.ddd.dal.condition.MbrOrderCountCondition;
import com.chuangjiangx.member.stored.ddd.dal.dto.MbrOrderCountInfo;
import com.chuangjiangx.member.stored.ddd.domain.model.MbrOrderType;
import com.sun.jmx.snmp.ThreadContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author cj-ch
 * @date 2018/6/26 下午3:15
 */
@RestController
@RequestMapping(value = "/api/mbr/count", produces = "application/json;charset=UTF-8")
public class MbrCountController extends BaseController {

    @Autowired
    private MbrCountQuery mbrCountQuery;


    @RequestMapping(value = "/order-info")
    @Login
    public Response orderInfo(MbrOrderCountInfoRequest request){
        ThreadLocalUser user = (ThreadLocalUser) ThreadContext.get(Constants.CURRENT_LOGIN_USER_KEY);
        MbrOrderCountCondition condition = new MbrOrderCountCondition();
        condition.setOrderNumber(request.getOrderNumber());
        condition.setMobile(request.getMobile());
        condition.setStoreId(request.getStoreId());
        condition.setStartTime(request.getStartTime());
        condition.setEndTime(request.getEndTime());

        condition.setType(MbrOrderType.CONSUME.value);
        condition.setMerchantId(user.getMerchantId());
        condition.setStoreId(user.getStoreId());
        condition.setStoreUserId(user.getStoreUserId());
        condition.setStoreUserName(request.getStoreUserName());
        condition.setPayEntry(request.getPayEntry());

        MbrOrderCountInfo result = mbrCountQuery.webOrderCountInfo(condition);
        return ResponseUtils.successCamel(result);
    }

}
